#include "contacts.pb.h"
#include <iostream>
#include <string>

int main() {
    // 创建联系人对象并设置信息
    contacts::contact conn;
    conn.set_name("曾德飞");
    conn.set_score(60.6);
    conn.set_sn(10033);

    // 序列化为字符串
    std::string serializedData;
    if (conn.SerializeToString(&serializedData)) {
        std::cout << "序列化成功！数据大小: " << serializedData.size() << " 字节" << std::endl;

        // 直接从内存中的字符串解析
        contacts::contact result;
        if (result.ParseFromString(serializedData)) {
            std::cout << "解析成功！" << std::endl;
            std::cout << "姓名: " << result.name() << std::endl;
            std::cout << "分数: " << result.score() << std::endl;
            std::cout << "序号: " << result.sn() << std::endl;
        } else {
            std::cerr << "解析失败！" << std::endl;
        }
    } else {
        std::cerr << "序列化失败！" << std::endl;
    }

    return 0;
}